<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%api_route}}".
 *
 * @property integer $id
 * @property string $route
 * @property string $type
 * @property string $name
 * @property integer $created_at
 * @property integer $updated_at
 *
 * @property ApiRoleRoute[] $apiRoleRoutes
 * @property ApiRole[] $apiRoles
 */
class ApiRoute extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%api_route}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['route', 'type', 'name', 'created_at', 'updated_at'], 'required'],
            [['created_at', 'updated_at'], 'integer'],
            [['route'], 'string', 'max' => 200],
            [['type'], 'string', 'max' => 11],
            [['name'], 'string', 'max' => 200],
            [['route'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'route' => 'Route',
            'type' => 'Type',
            'name' => 'Name',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getApiRoleRoutes()
    {
        return $this->hasMany(ApiRoleRoute::className(), ['api_route_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getApiRoles()
    {
        return $this->hasMany(ApiRole::className(), ['id' => 'api_role_id'])->viaTable('{{%api_role_route}}', ['api_route_id' => 'id']);
    }
}
